﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LibFriesland_Campina_CRM;

public partial class ViewAttendanceTracking : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["account"] == null)
            Response.Redirect("login.aspx");
        if (!IsPostBack)
        {
            getSupervisor();
            pldAttendanceTracking.Visible = false;
        }
    }
    
    
    //Hien thi danh sach Supervisor
    protected void getSupervisor()
    {
                
        //Lay danh sach Supervisor
        List<BizSupervisor> sups = BizSupervisor.getAll();
        cboSupervisor.DataSource = sups;
        cboSupervisor.DataTextField = "name";
        cboSupervisor.DataValueField = "sup_charid";
        cboSupervisor.DataBind();
        
        //Tao dong chon mca dinh cho cboSupervisor
        ListItem item = new ListItem("--", "");
        cboSupervisor.Items.Add(item);
        cboSupervisor.SelectedIndex = cboSupervisor.Items.Count - 1;

        //Hien thi ngay hien tai
        dateTracking.Date = DateTime.Now;
    }
    
    //Nhấn nút xem thông tin chi tiết chấm công
    protected void btnViewAttendanceTracking_Click(object sender, EventArgs e)
    {
        //System.Web.UI.Control ucAttendanceTracking = new System.Web.UI.Control();
        //ucAttendanceTracking = Page.LoadControl("UserControls/UCAttendanaceTracking.ascx");
        //pldAttendanceTracking.Controls.Add(ucAttendanceTracking);
    }
    protected void customValidateDatetimeTracking_ServerValidate(object source, ServerValidateEventArgs args)
    {
        //Kiem tra ngay xem cham cong co lon hon ngay hien tai
        DateTime currDatetime = DateTime.Now.Date;
        DateTime trackingDatetime = dateTracking.Date.Date;
        if (trackingDatetime.CompareTo(currDatetime) <= 0)
        {
            args.IsValid = true;
            pldAttendanceTracking.Visible = true;
        }
        else
        {
            args.IsValid = false;
            pldAttendanceTracking.Visible = false;
        }
    }
}